

#include <iostream>

class Resources {
public:

	friend std::ostream& operator<<(std::ostream& out, const Resources& A);

	Resources(): data(nullptr),size(0)
	{
		std::cout << "default construct" << std::endl;
	}

	Resources(int size) : data(new int[size]), size(size)
	{
		for (int i = 0; i < size; i++) {
			data[i] = 0;
		}
		std::cout << "size construct" << std::endl;
	}

	Resources(int size, int num) : data(new int[size]), size(size)
	{
		for (int i = 0; i < size; i++) {
			data[i] = num;
		}
		std::cout << "size/sum construct" << std::endl;
	}

	Resources(Resources&& other) noexcept : data(other.data), size(other.size)
	{
		other.data = nullptr;
		other.size = 0;
		std::cout << "move construct" << std::endl;
	}

	Resources(Resources& other)
	{
		data = new int[other.size];
		for (int i = 0; i < other.size; i++) {
			data[i] = other.data[i];
		}
		size = other.size;
		std::cout << "copy construct" << std::endl;
	}

	Resources& operator=(Resources&& other) noexcept
	{
		if (this != &other) {
			delete[] data;
			data = other.data;
			size = other.size;
			other.data = nullptr;
			other.size = 0;
		}
		std::cout << "move operater =" << std::endl;
		return *this;
	}

	Resources& operator=(Resources& other)
	{
		delete[] data;
		data = new int[other.size];
		for (int i = 0; i < other.size; i++) {
			data[i] = other.data[i];
		}
		size = other.size;
		std::cout << "copy operater =" << std::endl;
		return *this;
	}

    void print()
    {
        std::cout << data << std::endl;
    }
	~Resources()
	{
		std::cout << "destructor" << std::endl;
		delete[] data;
	}
private:
	int* data;
	int size;
};

std::ostream& operator<<(std::ostream& out, const Resources& A)
{
	for (int i = 0; i < A.size; i++)
	{
		out << A.data[i] << " ";
	}
	return out;
}

Resources copy(Resources& A)
{
	Resources B(A);
	return B;
}

int main(void)
{
	Resources R1(10);

	{
		Resources R2;
		R2 = copy(R1);
	}

    std::cout << "break" << std::endl;
	{
    	copy(R1);
	}

    std::cout << "end" << std::endl;
	getchar();

	return 0;
}

